<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script crossorigin src="../js/react.production.min.js"></script>
    <!-- 核心库  最先引用 -->
    <script crossorigin src="../js/react-dom.production.min.js"></script>
    <!-- 引用react-dom 用于支持react操作DOM -->
    <script crossorigin src="../js/babel.min.js"></script>
    <!-- 引入babel 用于将jsx转为js -->
    <title>学习react</title>
</head>

<body>
    <div id="test"></div>
    <div id="test1"></div>
    <script type="text/babel">
        // 精简写法
        class MyDemo extends React.Component {
            state = { isHot: false }
            render() {
                return <h1 onClick={this.demo}>今天天气很{this.state.isHot ? '炎热' : '凉爽'}</h1>
            }
            demo = () => {
                this.setState({ isHot: !this.state.isHot });
            }
        }
        ReactDOM.render(<MyDemo />, document.getElementById("test"));
        // 完整写法
        // class MyDemo extends React.Component {
        //     constructor(props) {
        //         super(props);
        //         this.state = {
        //             isHot: false
        //         }
        //     }
        //     render() {
        //         return <h1 onClick={this.demo}>今天天气很{this.state.isHot ? '炎热' : '凉爽'}</h1>
        //     }
        //     demo = () => {
        //         console.log('点击了');
        //         this.setState({ isHot: !this.state.isHot });
        //     }
        // }
        // ReactDOM.render(<MyDemo />, document.getElementById("test"));
    </script>
</body>

</html>